<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<input type="text"  id="num" value="" />
		<input type="button"  onclick="compare()" value="猜" />
		<span id="result"></span>
		<script type="text/javascript">
			var random=parseInt(Math.random()*100+1);
			console.log(random);
			function compare(){
				// var value = parseInt(document.getElementById('num').value);
				var num=document.getElementById('num').value;
				var resultSpan = document.getElementById('result');
				
				if(num == '' || isNaN(num)) {
					resultSpan.innerHTML = '<b>请输入一个数字</b>';
					return;
				}
				
				if(num<random){
					resultSpan.innerHTML = '小了';
				}else if(num>random){
					resultSpan.innerHTML = '大了';
				}else{
					resultSpan.innerHTML = '猜对了 答案是'+random;
				}
			}
		</script>
	</body>
</html>
